//
//  MineDynamicCell.m
//  WeCommunity
//
//  Created by mac on 2017/6/20.
//  Copyright © 2017年 lzy. All rights reserved.
//

#import "MineDynamicCell.h"

@interface MineDynamicCell ()

@property (nonatomic,strong) NSMutableArray * dynamicImageViewArray;
@property (nonatomic,assign) CGFloat pointY;

@end

@implementation MineDynamicCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        self.backgroundColor = [UIColor whiteColor];
        
        self.pointY = 18;

        //动态发布时间
        self.timeLabel = [[UILabel alloc] init];
        self.timeLabel.frame = CGRectMake(0, self.pointY, 94, 32);
        self.timeLabel.font = PFM_FONT(32);
        self.timeLabel.textAlignment = NSTextAlignmentCenter;
        self.timeLabel.textColor = [UIColor blackColor];
        [self.contentView addSubview:self.timeLabel];
        
        //内容
        [self.contentView addSubview:self.contentLabel];
        
        [self.contentView addSubview:self.contentImageView];
        
        
    }
    return self;
}

-(YYLabel *)contentLabel
{
    if (!_contentLabel) {
        _contentLabel = [[YYLabel alloc] init];
        _contentLabel.font = PFR_FONT(14);
        _contentLabel.textColor = [UIColor blackColor];
        [self addSubview:_contentLabel];
    }
    return _contentLabel;
}

-(MineDynamicImageView *)contentImageView
{
    if (!_contentImageView) {
        _contentImageView = [[MineDynamicImageView alloc] initWithFrame:CGRectMake(CGRectGetMaxX(self.timeLabel.frame), self.pointY, KScreen_Width * 0.27, KScreen_Width * 0.27)];
        
    }
    return _contentImageView;
}

-(void)layoutViewWithModel:(DynamicModel *)model
{
    dispatch_async(dispatch_get_main_queue(), ^{
        self.timeLabel.text = model.formatTime2;
        
        if (model.imageList.count > 0) {
            self.contentImageView.hidden = NO;
            self.contentImageView.dynamicModel = model;
        }else{
            self.contentImageView.hidden = YES;
        }
        
        if (model.content.length > 0) {
            self.contentLabel.hidden = NO;
            
            if (model.imageList.count > 0) {
                self.contentLabel.frame = CGRectMake(CGRectGetMaxX(self.contentImageView.frame) + 5 , self.pointY, KScreen_Width - CGRectGetMaxX(self.contentImageView.frame) - 10,64);
            }else{
                self.contentLabel.frame = CGRectMake(CGRectGetMaxX(self.timeLabel.frame),self.pointY, KScreen_Width - CGRectGetMaxX(self.timeLabel.frame) - 10, 64);
            }
            self.contentLabel.text = model.content;
            self.contentLabel.lineBreakMode = NSLineBreakByCharWrapping; //换行格式
            self.contentLabel.numberOfLines = 3;
            [self.contentLabel sizeToFit];
        }else{
            self.contentLabel.hidden = YES;
            self.contentLabel.frame = CGRectMake(0, 0, 0, 0);
        }
    });
}


@end
